package com.ruoyi.act.module.controller;

import cn.hutool.crypto.digest.MD5;
import com.ruoyi.act.module.domain.ActBizInfo;
import com.ruoyi.act.module.service.IActBizInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作流租户Controller
 *
 * @author hcj
 * @date 2020-12-24
 */
@Api("测试")
@RestController
@RequestMapping("/module/info")
public class ActBizInfoController extends BaseController {
    @Autowired
    private IActBizInfoService actBizInfoService;

    /**
     * 查询工作流租户列表
     */
    @ApiOperation("获取列表")
    @PreAuthorize("@ss.hasPermi('module:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActBizInfo actBizInfo) {
        startPage();
        List<ActBizInfo> list = actBizInfoService.selectActBizInfoList(actBizInfo);
        return getDataTable(list);
    }

    /**
     * 获取租户信息
     *
     * @param actBizInfo
     * @return
     */
    @ApiOperation("获取租户信息")
    @GetMapping("/tenant")
    public List<ActBizInfo> tenant(ActBizInfo actBizInfo) {
        actBizInfo.setStatus("1");//启用的
        return actBizInfoService.selectActBizInfoList(actBizInfo);
    }

    /**
     * 导出工作流租户列表
     */
    @PreAuthorize("@ss.hasPermi('module:info:export')")
    @Log(title = "工作流租户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ActBizInfo actBizInfo) {
        List<ActBizInfo> list = actBizInfoService.selectActBizInfoList(actBizInfo);
        ExcelUtil<ActBizInfo> util = new ExcelUtil<ActBizInfo>(ActBizInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取工作流租户详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(actBizInfoService.selectActBizInfoById(id));
    }

    /**
     * 新增工作流租户
     */
    @PreAuthorize("@ss.hasPermi('module:info:add')")
    @Log(title = "工作流租户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActBizInfo actBizInfo) {
        actBizInfo.setPassword(MD5.create().digestHex(actBizInfo.getPassword()));
        return toAjax(actBizInfoService.insertActBizInfo(actBizInfo));
    }

    /**
     * 修改工作流租户
     */
    @PreAuthorize("@ss.hasPermi('module:info:edit')")
    @Log(title = "工作流租户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActBizInfo actBizInfo) {
        return toAjax(actBizInfoService.updateActBizInfo(actBizInfo));
    }

    /**
     * 删除工作流租户
     */
    @PreAuthorize("@ss.hasPermi('module:info:remove')")
    @Log(title = "工作流租户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(actBizInfoService.deleteActBizInfoByIds(ids));
    }
}
